import string
import threading
import time


def count():
    c = 1
    for i in range(5):
        print(c, "#")
        #if i%2:
        yield c,c,c
        c += 1


def char():
    s = string.ascii_lowercase
    for c in s:
        print(c, "*")
        yield c


t1 = count()
t2 = char()

tasks = {"t1":t1, "t2":t2}


def add_task():
    tasks["t300"] = count()
def event_loop():
    while True:
        if len(tasks) == 0:
            print("I sleep")
            time.sleep(1)
            continue

        pops = []
        for name, task in tasks.items():
            if next(task, None) is None:
                #tasks.pop(name)
                pops.append(name)
                print("task {} finished".format(name))

        for name in pops:
            tasks.pop(name)

event_loop()

#threading.Thread(target=event_loop, name="eventloop").start()
#time.sleep(10)
#tasks["t400"] = char()
print('~' * 30)